class Solution:
    def containsNearbyDuplicate(self, nums, k: int) -> bool:
        dic = {}
        for i in range(len(nums)):
            if nums[i] in dic:
                if i - dic[nums[i]] <= k:
                    return True
            dic[nums[i]] = i
        return False


if __name__ == '__main__':
    so = Solution()
    nums = [1,2,3,1,2,3]
    k = 2
    r = so.containsNearbyDuplicate(nums, k)
    print(r)
